//
//  LXPreparePayViewCell.m
//  LvXi_newVersion
//
//  Created by 诸葛孔明 on 16/8/11.
//  Copyright © 2016年 SJT. All rights reserved.
//............................................................................................//
//......................................个人中心待付款/待收货/全部订单cell......................................//
//............................................................................................//

#import "LXPreparePayViewCell.h"

#import "LXMineCenterButton.h"

#import "NSObject+LXExtension.h"

#import "LXPrepareGetGoodsViewController.h"

#import "LXPreparePayViewController.h"

#import "LXAllOrderViewController.h"



@interface LXPreparePayViewCell ()

@property(nonatomic,weak)LXMineCenterButton *preparePayBtn;//待付款
@property(nonatomic,weak)LXMineCenterButton *prepareGetGoodBtn;//待收货
@property(nonatomic,weak)LXMineCenterButton *AllOrderBtn;//全部订单

@property(nonatomic,strong)NSArray *imageArray;
@property(nonatomic,strong)NSArray *titles;

@end

@implementation LXPreparePayViewCell

- (NSArray *)imageArray
{
    if (!_imageArray) {
        _imageArray = @[@"payment",@"goods",@"order"];
    }
    return _imageArray;
}

- (NSArray *)titles
{
    if (!_titles) {
        _titles = @[@"待付款",@"待收货",@"全部订单"];
    }
    return _titles;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        LXMineCenterButton *prepareGetGoodBtn = [[LXMineCenterButton alloc] init];
        [prepareGetGoodBtn setImage:[UIImage imageNamed:@"goods"] forState:UIControlStateNormal];
        [prepareGetGoodBtn setTitle:@"待收货" forState:UIControlStateNormal];
        [prepareGetGoodBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.prepareGetGoodBtn = prepareGetGoodBtn;
        [self addSubview:prepareGetGoodBtn];
        
        LXMineCenterButton *preparePayBtn = [[LXMineCenterButton alloc] init];
        [preparePayBtn setImage:[UIImage imageNamed:@"payment"] forState:UIControlStateNormal];
        [preparePayBtn setTitle:@"待付款" forState:UIControlStateNormal];
        [preparePayBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.preparePayBtn = preparePayBtn;
        [self addSubview:preparePayBtn];
        
        LXMineCenterButton *AllOrderBtn = [[LXMineCenterButton alloc] init];
        [AllOrderBtn setImage:[UIImage imageNamed:@"order"] forState:UIControlStateNormal];
        [AllOrderBtn setTitle:@"全部订单" forState:UIControlStateNormal];
        [AllOrderBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.AllOrderBtn = AllOrderBtn;
        [self addSubview:AllOrderBtn];
        
        UILabel* preparePayLabel = [UILabel labelWithTextColor:[UIColor whiteColor] backGroundColor:[UIColor redColor] font:[UIFont systemFontOfSize:12]];
        [preparePayBtn addSubview:preparePayLabel];
        
        UILabel* prepareGetGoodLabel = [UILabel labelWithTextColor:[UIColor whiteColor] backGroundColor:[UIColor redColor] font:[UIFont systemFontOfSize:12]];
        [prepareGetGoodBtn addSubview:prepareGetGoodLabel];
        
        UILabel* AllOrderLabel = [UILabel labelWithTextColor:[UIColor whiteColor] backGroundColor:[UIColor redColor] font:[UIFont systemFontOfSize:12]];
        [AllOrderBtn addSubview:AllOrderLabel];
        
        
        self.preparePayLabel = preparePayLabel;
        self.prepareGetGoodLabel = prepareGetGoodLabel;
        self.AllOrderLabel = AllOrderLabel;
        
        UIImageView * backGroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(globalMargin, 0, ScreenWidth-2*globalMargin,MineRatio(88))];
        backGroundImageView.image = [UIImage imageWithColor:[UIColor whiteColor] size:backGroundImageView.size];
        [backGroundImageView addRadius:10];
        [self.contentView insertSubview:backGroundImageView atIndex:0];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //待收货
    self.prepareGetGoodBtn.y = 0;
    self.prepareGetGoodBtn.width = MineRatio(70);
    self.prepareGetGoodBtn.height = self.height;
    self.prepareGetGoodBtn.x = self.width * 0.5 - self.prepareGetGoodBtn.width * 0.5;
    
    //待收货小球
    self.prepareGetGoodLabel.width = MineRatio(18);
    self.prepareGetGoodLabel.height = MineRatio(18);
    self.prepareGetGoodLabel.x = self.prepareGetGoodBtn.width - self.prepareGetGoodLabel.width ;
    self.prepareGetGoodLabel.y = MineRatio(10);
    [self.prepareGetGoodLabel addRadius:self.prepareGetGoodLabel.width * 0.5];

    //待付款
    self.preparePayBtn.y = self.prepareGetGoodBtn.y;
    self.preparePayBtn.width = self.prepareGetGoodBtn.width;
    self.preparePayBtn.height = self.prepareGetGoodBtn.height;
    self.preparePayBtn.x = (self.prepareGetGoodBtn.x - self.preparePayBtn.width) * 0.5;
    
    //待付款小球
    self.preparePayLabel.width = self.prepareGetGoodLabel.width;
    self.preparePayLabel.height = self.prepareGetGoodLabel.height;
    self.preparePayLabel.x = self.preparePayBtn.width - self.preparePayLabel.width ;
    self.preparePayLabel.y = self.prepareGetGoodLabel.y;
    [self.preparePayLabel addRadius:self.preparePayLabel.width * 0.5];
    
    //全部订单
    self.AllOrderBtn.y = self.prepareGetGoodBtn.y;
    self.AllOrderBtn.width = self.prepareGetGoodBtn.width;
    self.AllOrderBtn.height = self.prepareGetGoodBtn.height;
    self.AllOrderBtn.x = self.prepareGetGoodBtn.right + self.preparePayBtn.x;

    //全部订单小球
    self.AllOrderLabel.width = self.prepareGetGoodLabel.width;
    self.AllOrderLabel.height = self.prepareGetGoodLabel.height;
    self.AllOrderLabel.x = self.AllOrderBtn.width - self.AllOrderLabel.width ;
    self.AllOrderLabel.y = self.prepareGetGoodLabel.y;
    [self.AllOrderLabel addRadius:self.AllOrderLabel.width * 0.5];
    
    LXUser * user = [LXUser shareUser];
    
    if([user.ordernotpaye floatValue]==0){
        self.preparePayLabel.hidden = YES;
    }else{
        self.preparePayLabel.hidden = NO;
        self.preparePayLabel.text = user.ordernotpaye;
    }
    
    self.prepareGetGoodLabel.hidden = YES;
    
    if([user.orederall floatValue]==0){
        self.AllOrderLabel.hidden = YES;
    }else{
        self.AllOrderLabel.hidden = NO;
        self.AllOrderLabel.text = user.orederall;
    }
}

#pragma mark - 按钮点击事件
//.....................................点击按钮跳转到不同控制器......................................//

- (void)buttonClick:(LXMineCenterButton *)button
{
    UIViewController *vc = [self getCurrentVC];
    //MARK:待收货控制器
    LXPrepareGetGoodsViewController *prepareGetGoodsVc = [[LXPrepareGetGoodsViewController alloc] init];
    //MARK:待付款控制器
    LXPreparePayViewController *preparePayVc = [[LXPreparePayViewController alloc] init];
    //MARK:全部订单控制器
    LXAllOrderViewController *allOrderVc = [[LXAllOrderViewController alloc] init];
    
    if ([button.currentTitle isEqualToString:@"待收货"]) {
        [vc.navigationController pushViewController:prepareGetGoodsVc animated:YES];

    }else if ([button.currentTitle isEqualToString:@"待付款"]){
        [vc.navigationController pushViewController:preparePayVc animated:YES];

    }else{
        [vc.navigationController pushViewController:allOrderVc animated:YES];

    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];

}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    
}

@end
